package van.planifolia.demo02;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;

/**
 * Created by Intellij IDEA<br>
 *
 * @author Planifolia.Van
 * @version 1.0
 * @date 2022/10/27 17:56
 */
public class ReflexOperationMethods {
    public static void main(String[] args) throws InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
        Class<Animal> animalClass = Animal.class;
        Class<Tiger> tigerClass = Tiger.class;

        Animal animal = animalClass.newInstance();
        Tiger tiger = tigerClass.newInstance();

        Method show = tigerClass.getMethod("show");
        show.invoke(tiger);
        Method[] methods = tigerClass.getMethods();
        Arrays.stream(methods).forEach(System.out::println);

        Method getType = animalClass.getDeclaredMethod("getType", String.class);
        getType.setAccessible(true);
        Object result = getType.invoke(animal, "哺乳类");
        System.out.println(result);
        Arrays.stream(animalClass.getDeclaredMethods()).forEach(System.out::println);


    }
}
class Animal{
    private String getType(String type){
        System.out.println("类型为" + type);
        return type;
    }
    public void show(){
        System.out.println("show");
    }
}
class Tiger extends Animal{
    private String getName(String name){
        System.out.println("名字为" + name);
        return name;
    }
    public void getAge(){
        System.out.println("年龄为");
    }
}